#ifndef __CACHEFLEX_INTERNAL_TYPES__
#define  __CACHEFLEX_INTERNAL_TYPES__
#include <stdio.h>
#include "include/base-api/cf_base_types.h"
#include "devel-headers/cf_frame_types.h"

#define CF_MULTI_STORE_SIZE 512 * 1024 * 1024

typedef struct cf_index
{
    struct cf_index_interface interface;
    void *instance;
} cf_index_t;

typedef struct cf_store
{
    struct cf_store_interface interface;
    void *instance;
} cf_store_t;

typedef struct cf_reclaim
{
    struct cf_reclaim_interface interface;
    void *instance;
} cf_reclaim_t;

struct cacheflex
{
  int64_t cache_size_limit;
  int64_t item_num_limit;
  cf_kv_ops_t *kv_ops;
  cf_index_t index;
  cf_store_t store;
  cf_reclaim_t reclaim;
  cf_generic_alloc_pt alloc;
  cf_generic_free_pt free;
  cf_write_log_pt write_log;
};

#ifndef __CACHEFLEX_BASE_TYPES__
typedef struct cacheflex cacheflex_t;
#endif

#define CF_INDEX(func, args...) cache->index.interface.func(cache->index.instance, args)
#define CF_STORE(func, args...) cache->store.interface.func(cache->store.instance, args)
#define CF_RECLAIM(func, args...) cache->reclaim.interface.func(cache->reclaim.instance, args)

#define CF_WRITE_LOG(level, fmt, args...) \
({ \
    if (NULL != cache && NULL != cache->write_log) \
    { \
        cache->write_log(level, "[CF][%s][%s][%d] " fmt, __FILE__, __FUNCTION__, __LINE__, ##args); \
    } \
    else \
    { \
        fprintf(stderr, "*[%s][%s] %s [CF][%s][%s][%d] " fmt "\n", __DATE__, __TIME__, #level, \
                __FILE__, __FUNCTION__, __LINE__, ##args); \
    } \
})

#endif //__CACHEFLEX_INTERNAL_TYPES__

